package com.sparrow.source.common.dto;

import com.sparrow.source.common.enums.ResultEnum;

import java.io.Serializable;

/**
 * @author bryceyung
 * @since 2024/11/16
 */
public class Result implements Serializable {

    /**
     * 私有化构造，保证都按统一的方式生成ResultWrapper
     */
    private Result() {
    }

    /**
     * 操作信息
     */
    private String message;

    /**
     * 附帶数据
     */
    private Object object;

    /**
     * 相应码
     */
    private Integer code;

    public Result setMessage(String message) {
        this.message = message;
        return this;
    }

    public Result setObject(Object object) {
        this.object = object;
        return this;
    }

    public String getMessage() {
        return message;
    }

    public Object getObject() {
        return object;
    }

    public Integer getCode() {
        return code;
    }

    /**
     * 设置code的方法私有化，保证code都从枚举里获取
     *
     * @param code
     */
    private void setCode(Integer code) {
        this.code = code;
    }

    public static Result build(ResultEnum resultEnum) {
        Result result = new Result();
        result.setCode(resultEnum.getCode());
        result.setMessage(resultEnum.getDesc());
        return result;
    }


}
